#pragma once
#include <vector>
#include <unordered_map>
#include"TimeStamp.h"
#include"nocopy.h"
class EventLoop;
class Channel;
class Poller : nocopyable
{
public:
    using ChannelList = std::vector<Channel *>;
    Poller(EventLoop *loop) ;
    virtual ~Poller() ;
    // 给所有的IO复用保留统一的接口
    virtual TimeStamp poll(int timeoutMs, ChannelList *activeChannells) = 0;
    virtual void updateChannel(Channel *channel) = 0;
    virtual void removeChannel(Channel *channel) = 0;
    // 判断channel是否在当前Poller中
    bool hasChannel(Channel *channel) const;
    
    // EventLoop获取默认的IO复用实现
    static Poller *newDefaultPoller(EventLoop *loop);

protected:
    using ChannelMap = std::unordered_map<int, Channel *>;
    ChannelMap channels_;

private:
    EventLoop *ownLoop_; // 定义poller所属的事件循环
};